<?php
/**
 * Created by PhpStorm.
 * User: zhou
 * Date: 2019/3/26
 * Time: 下午6:02
 */

namespace App\Models;


use Illuminate\Database\Eloquent\Model;

class TransactionLog extends Model
{
    protected $table = 'transaction_logs';
    protected $fillable = ['order_sn','log_status','money','updated_at','created_at','hotel_open_id','hotel_owner_id'];

    const LOG_DISTRIBUTION = 0; //会员消费，酒店拿到销售额的分成
    const LOG_APPLY_CASH = 1;   //申请提现
    const LOG_CASH_PASS = 2;   // 提现成功
    const LOG_REJECT_CASH = 3; //拒绝提现
    const LOG_REFUND = 4;      //退款

    public static $log_status_map = [
        self::LOG_DISTRIBUTION => '会员消费分成',
        self::LOG_APPLY_CASH => '申请提现',
        self::LOG_CASH_PASS => '已提现',
        self::LOG_REJECT_CASH => '提现被拒',
        self::LOG_REFUND => '退款',
    ];

    /**添加日志方法
     * @param $data
     * @return bool
     */
    public  function add_logs($data)
    {
        if(self::query()->create($data)){
            return true;
        }
        return false;
    }

    /**前端获取金额流水情况
     * @param $post
     * @return array
     */
    public static function get_logs($post)
    {
        $query = self::query()
            -> orderBy('created_at','desc');
        foreach($post as $field => $v){
            $query -> where($field,'=',$v);
        }
        $list = $query -> get() -> toArray();
        foreach($list as &$v){
            $v['status_explain'] = self::$log_status_map[$v['log_status']];
        }
        return $list;
    }

}